from base.base import Base


# ----------------角色管理----------------

class page_role_management(Base):

    def click_role_management(self):
        self.switch_node("role_management")
        self.click('role_manage')
        self.logger.info("点击角色管理")

    # 模糊查询
    def fuzzy_query(self, name):
        self.switch_node("role_management")
        self.click('role_manage')
        self.logger.info("点击角色管理")
        self.send_keys('role_query', name)
        self.logger.info('输入角色名称')
        self.keys_enter('role_query')
        self.logger.info("点击查询按钮")

    # 添加角色
    def add_role(self, name, coding, desc):
        self.switch_node("role_management")
        self.click('role_manage')
        self.logger.info("点击角色管理")
        self.click('add_role')
        self.logger.info("点击添加角色")
        self.send_keys('role_name', name)
        self.logger.info("输入角色名称")
        self.send_keys('role_coding', coding)
        self.logger.info("输入角色编码")
        self.send_keys('role_desc', desc)
        self.logger.info("输入角色描述")
        self.click('role_save')
        self.logger.info("点击保存按钮")
        self.click('ok')


    # 为角色分配权限
    def assign_permissions(self):
        self.switch_node("role_management")
        self.click('role_manage')
        self.logger.info("点击角色管理")
        self.click('assign_permissions')
        self.logger.info("点击分配权限")
        self.click('permissions_1')
        self.logger.info("点击权限1")
        self.click('permissions_2')
        self.logger.info("点击权限2")
        self.click('assign_permission_save')
        self.logger.info("点击保存按钮")
        self.click('ok')

    # 编辑角色
    def edit_role(self,coding):
        self.switch_node("role_management")
        self.click('role_manage')
        self.logger.info("点击角色管理")
        self.click('role_modify')
        self.logger.info("点击编辑角色")
        self.send_keys('modify_encoding',coding)
        self.logger.info("修改角色编码")
        self.click('modify_save')
        self.logger.info("点击保存按钮")
        self.click('ok_modify')
    # 删除角色
    def delete_role(self):
        self.switch_node("role_management")
        self.click('role_manage')
        self.logger.info("点击角色管理")
        self.click('delete_role')
        self.logger.info("点击删除角色")
        self.click('confirm_delete')
        self.logger.info("点击确认删除按钮")
        self.click('ok')

    def get_name(self):
        self.switch_node("role_management")
        return self.text('get_role_name')

    def get_role_coding(self):
        self.switch_node("role_management")
        return self.text('get_role_coding')
